define(["text!/components/template/lv1_btn.html","sdata"], function(template,sdata) {
    console.log('lv1_btn define')
    let config = {'root_img_src':'/img/btn/'}
    let vueExtend = function(resolve, reject) {
        console.log('lv1_btn resolve')
        resolve({
            template: template,
            props:['btn_name'],
            data: function() {
                console.log('lv1_btn data',sdata)
                let rootNode = this.$root.$el;
                return { 
                    display_mode:1,
                    name: rootNode.getAttribute('id'),
                    tagData: sdata.getTagDataByTag(rootNode.getAttribute('data-opt-tag'))
                };
            },
            methods:{
                changeStatus:function() {
                    console.log('changestatus')
                    // sdata.getTagDataByTag(this.$root.$el.getAttribute('data-opt-tag')).set('a01',3)
                    // this.$set(this.tagData,'a01',4)
                },
                show:function () {
                    console.log('show')
                },
                btnClick: function() {
                    console.log('btn click ',this.btn_name)
                    this.$store.commit('setCurrentLv1',this.btn_name)
                }
            },
            computed:{
                img_src :function () {
                    console.log('img_src')
                    return config.root_img_src + this.btn_name + '-' + this.display_mode + '.png'
                },
                currentLv1_menu : function () {
                    return this.$store.state.currentLv1
                }
            },
            watch:{
                "$store.state.currentLv1" : function() {
                    console.log('watch '+this.btn_name)
                    if(this.currentLv1_menu == this.btn_name)
                    {
                        this.display_mode = 2
                    }else{
                        this.display_mode = 1
                    }
                }
            },
            beforeCreate: function() {
                console.log('lv1_btn before created:'+this)
                let rootNode = this.$root.$el
                let deviceTag = rootNode.getAttribute('data-opt-tag')
                console.log('lv1_btn deviceTag:',deviceTag)
                // sdata.setTagMapWithAttrList(deviceTag,config)
                sdata.addToVueRefMap(deviceTag,this)
                console.log('lv1 btn store:',this.$store)
            },
            created: function() {
                console.log(this.btn_name)
                this.img_src = config.root_img_src+this.btn_name+'-1.png'
            }
        })
    }
    
    return{vueExtend,config}
})